<template>
  <div class="app-container">


    <el-table v-loading="loading" :data="taskList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="任务名称" align="center" prop="assignee" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >审批通过</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
          >审批未通过</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listTask,getTask,adminexamine,financeexamine } from "@/api/variety/task";

export default {
  name: "Task",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      taskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      taskId:null,
      aid:null,
      pd:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rev: null,
        executionId: null,
        procInstId: null,
        procDefId: null,
        name: null,
        parentTaskId: null,
        description: null,
        taskDefKey: null,
        owner: null,
        assignee: null,
        delegation: null,
        priority: null,
        createTime: null,
        dueDate: null,
        category: null,
        suspensionState: null,
        tenantId: null,
        formKey: null,
        claimTime: null,
        roleId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.roleId = this.$store.state.user.roles[0];
      this.loading = true;
      if (this.roleId == "b") {
        this.assignee = "administrators_002";
      } else {
        this.assignee = "finance_003";
      }
      console.log(this.roleId, this.assignee);
      getTask(this.assignee).then(response => {
        this.taskList = response;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rev: null,
        executionId: null,
        procInstId: null,
        procDefId: null,
        name: null,
        parentTaskId: null,
        description: null,
        taskDefKey: null,
        owner: null,
        assignee: null,
        delegation: null,
        priority: null,
        createTime: null,
        dueDate: null,
        category: null,
        suspensionState: null,
        tenantId: null,
        formKey: null,
        claimTime: null
      };
      this.resetForm("form");
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.taskId = row.id;
      this.aid = row.assignee;
      this.pd = false;
      if (this.roleId == "b") {
        adminexamine(this.taskId, this.aid, this.pd).then(response => {
          this.form = response;
          if (response != null) {
            alert("审核成功！！")
          }
        });
      } else {
        financeexamine(this.taskId, this.aid, this.pd).then(response => {
          this.form = response;
          if (response != null) {
            alert("审核成功！！")
          }
        });
      }
      this.getList();
    },
    /**  */
    /**  */
    handleUpdate(row) {
      this.taskId=row.id;
      this.aid=row.assignee;
      this.pd=true;
      if (this.roleId=="b"){
        adminexamine(this.taskId,this.aid,this.pd).then(response => {
          this.form = response;
          if (response!=null){
            alert("审核成功！！")
          }
        });
        this.getList();
      }else {
        financeexamine(this.taskId,this.aid,this.pd).then(response => {
          this.form = response;
          if (response!=null){
            alert("审核成功！！")
          }
        });
        this.getList();
      }

    },
  }
};
</script>

<!--}else {-->
<!--          financeexamine(this.taskId,this.aid,this.pd).then(response => {-->
<!--            this.form = response;-->
<!--            if (response!=null){-->
<!--              alert("审核成功！！")-->
<!--            }-->
<!--          });-->
<!--          this.getList();-->
<!--        }-->
